/*
 * This packet is a rejection of a previous login attempt.
 *
 * @author Jonathan Walsh (jwalsh8484@gmail.com)
 */

package egs.packets;

import java.nio.ByteBuffer;

public class AuthLoginErrPacket extends Packet {

    /*
    public enum ReasonCode { 
	invalid_login (1,"invalid_login"),
	    protocol_error (2,"protocol_error"),
	    resource_shortage (3,"resource_shortage"), 
	    server_error (4,"server_error");
	public final int value;
	public final String value_str;
	ReasonCode( int value, String value_str ) { 
	    this.value = value;
	    this.value_str = value_str;
	};
    };
    */
    public enum ReasonCode { 
        invalid_login (1),
            protocol_error (2),
            resource_shortage (3),
            server_error (4);
        public final int value;
        ReasonCode( int value ) {
            this.value = value;
        };
    };
    
    private ReasonCode reason_code;
    
    public AuthLoginErrPacket( ReasonCode reason_code ) {
        this.reason_code = reason_code;

        /*Set up the header*/
        message_type = MSG_AUTH_LOGIN_ERR;
        game_name = 0;
        game_version = 0;
        data_area_size = 4; /*only one int in this packet*/
    }
    
    public AuthLoginErrPacket( byte[] raw ) {
        ByteBuffer buf = setHeaderNew( raw );
        int val_from_packet = buf.getInt( HEADER_SIZE );
        reason_code = ReasonCode.class.getEnumConstants()[val_from_packet-1];
    }
	
    public byte[] getRaw() {
        ByteBuffer buf = makeBufferWithHeader( data_area_size );
        buf.putInt( reason_code.value );
        
        return buf.array();
    }
    
    public String toString() {
        return super.toString() + "\nreason_code = " + reason_code.value;
    }
    
    public ReasonCode get_reason_code() { return reason_code; }
    
}
